package com.bible.fire.api.baidumap;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;

import com.baidu.mapapi.map.ItemizedOverlay;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.OverlayItem;
import com.baidu.platform.comapi.basestruct.GeoPoint;
import com.baidu.platform.comapi.map.Projection;

/**
 * 用来在百度地图上标注位置
 * @author zhangyp
 *
 */
public class OverlayItem4BMap extends ItemizedOverlay{
	
	private List<OverlayItem> mGeoList = new ArrayList<OverlayItem>();

	public OverlayItem4BMap(Drawable marker, MapView mapView, Context context, GeoPoint pt, String title) {
		super(marker, mapView);
		OverlayItem item = new OverlayItem(pt, title, "");
		item.setMarker( marker );
		addItem( item );
		mGeoList.add( item );
		//执行填充方法
		//populate();
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mGeoList.get(i);
	}

	@Override
	public int size() {
		return mGeoList.size();
	}
	
	//@Override 旧版本中的方法  用来绘制的 
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {  
        //super.draw(canvas, mapView, shadow);  
        // Projection接口用于屏幕像素点坐标系统和地球表面经纬度点坐标系统之间的变换 
    	
        Projection projection = mapView.getProjection();  
        // 遍历所有的OverlayItem   
        for (int index = this.size() - 1; index >= 0; index--) {  
            // 得到给定索引的item   
            OverlayItem overLayItem = getItem(index);  
  
            // 把经纬度变换到相对于MapView左上角的屏幕像素坐标   
            Point point = projection.toPixels(overLayItem.getPoint(), null);  
  
            Paint paintText = new Paint();  
            paintText.setColor(Color.RED);  
            paintText.setTextSize(13);  
            // 绘制文本   
            canvas.drawText(overLayItem.getTitle(), point.x + 10, point.y - 15, paintText);  
        }  
    }

}
